package com.niiwoo.civet.scheduler.trigger;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.dubbo.rpc.RpcContext;
import com.niiwoo.civet.trade.service.newRefund.RefundHelperDubboService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 还款job
 * @author wangjun
 */

@Slf4j
@Component
public class RefundJobTrigger
{

    @Reference(version = "1.0.0")
    private RefundHelperDubboService refundHelperDubboService;

    /**
     * 0:15非全额划扣
     */
    @Scheduled(cron = "${newRefund.scheduled-run-partialRefund}")
    public void partialRefund()
    {
        log.info("0:15非全额划扣 start");
        RpcContext.getContext().asyncCall(() -> refundHelperDubboService.partialRefund());
    }

    /**
     * 02：00垫付job
     */
    @Scheduled(cron = "${newRefund.scheduled-run-compensatoryRefund}")
    public void compensatoryRefund()
    {
        log.info("02：00垫付 start");
        RpcContext.getContext().asyncCall(() -> refundHelperDubboService.compensatoryRefund());
    }


    /**
     * 16：00,21：00代扣
     */
    @Scheduled(cron = "${newRefund.scheduled-run-withhold}")
    public void withhold()
    {
        log.info("代扣 start");
        RpcContext.getContext().asyncCall(() -> refundHelperDubboService.withhold());
    }

    /**
     * 07:00 代扣逾期50天
     */
    @Scheduled(cron = "${newRefund.scheduled-run-withholdForOverdue50Day}")
    public void withholdForOverdue50Day()
    {
        log.info("代扣逾期50天 start");
        RpcContext.getContext().asyncCall(() -> refundHelperDubboService.withholdForOverdue50Day());
    }

    /**
     * 18：00,23：00全额划扣
     */
    @Scheduled(cron = "${newRefund.scheduled-run-fullRefund}")
    public void fullRefund()
    {
        log.info("全额划扣 start");
        RpcContext.getContext().asyncCall(() -> refundHelperDubboService.fullRefund());
    }

    /**
     * 每10分钟执行一次
     * 代扣充值补单
     */
    @Scheduled(cron = "${newRefund.scheduled-run-withholdSupplement}")
    public void withholdSupplement()
    {
        log.info("代扣充值补单 start");
        RpcContext.getContext().asyncCall(() -> refundHelperDubboService.withholdSupplement());
    }


    /**
     * 每10分钟执行一次
     * 还款订单记账补单
     */
    @Scheduled(cron = "${newRefund.scheduled-run-accountingSupplement}")
    public void accountingSupplement()
    {
        log.info("记账补单 start");
        RpcContext.getContext().asyncCall(() -> refundHelperDubboService.accountingSupplement());
    }

    /**
     * 每10分钟执行一次
     * 还款订单明细记账补单
     */
    @Scheduled(cron = "${newRefund.scheduled-run-accDetailSupplement}")
    public void accDetailSupplement()
    {
        log.info("记账明细补单 start");
        RpcContext.getContext().asyncCall(() -> refundHelperDubboService.accDetailSupplement());
    }

    /**
     * 日切（日切后自动更新罚息）
     */
    @Scheduled(cron = "${newRefund.scheduled-run-cutDate}")
    public void cutDateJob()
    {
        log.info("cutDate start,更新罚息");
        RpcContext.getContext().asyncCall(() -> refundHelperDubboService.cutDateForOverduePenalty());

    }

    /**
     * 罚息补单扫描
     */
    @Scheduled(cron = "${newRefund.scheduled-run-repeatUpdatePenaltyFee}")
    public void handFailedPenaltyUpdater()
    {
        log.info("repeatUpdatePennaltyFee start");
        refundHelperDubboService.repeatUpdatePenaltyFee();
    }
}